package cn.iocoder.yudao.module.biz.service.htPlanDetailexeannexs;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import java.util.*;
import cn.iocoder.yudao.module.biz.controller.admin.htPlanDetailexeannexs.vo.*;
import cn.iocoder.yudao.module.biz.dal.dataobject.htPlanDetailexeannexs.HtPlanDetailexeannexsDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;

import cn.iocoder.yudao.module.biz.convert.htPlanDetailexeannexs.HtPlanDetailexeannexsConvert;
import cn.iocoder.yudao.module.biz.dal.mysql.htPlanDetailexeannexs.HtPlanDetailexeannexsMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.biz.enums.ErrorCodeConstants.*;

/**
 * 隐患排查计划执行结果附件 Service 实现类
 *
 * @author riven
 */
@Service
@Validated
public class HtPlanDetailexeannexsServiceImpl implements HtPlanDetailexeannexsService {

    @Resource
    private HtPlanDetailexeannexsMapper htPlanDetailexeannexsMapper;

    @Override
    public Integer createHtPlanDetailexeannexs(HtPlanDetailexeannexsCreateReqVO createReqVO) {
        // 插入
        HtPlanDetailexeannexsDO htPlanDetailexeannexs = HtPlanDetailexeannexsConvert.INSTANCE.convert(createReqVO);
        htPlanDetailexeannexsMapper.insert(htPlanDetailexeannexs);
        // 返回
        return htPlanDetailexeannexs.getId();
    }

    @Override
    public void updateHtPlanDetailexeannexs(HtPlanDetailexeannexsUpdateReqVO updateReqVO) {
        // 校验存在
        this.validateHtPlanDetailexeannexsExists(updateReqVO.getId());
        // 更新
        HtPlanDetailexeannexsDO updateObj = HtPlanDetailexeannexsConvert.INSTANCE.convert(updateReqVO);
        htPlanDetailexeannexsMapper.updateById(updateObj);
    }

    @Override
    public void deleteHtPlanDetailexeannexs(Integer id) {
        // 校验存在
        this.validateHtPlanDetailexeannexsExists(id);
        // 删除
        htPlanDetailexeannexsMapper.deleteById(id);
    }

    private void validateHtPlanDetailexeannexsExists(Integer id) {
        if (htPlanDetailexeannexsMapper.selectById(id) == null) {
            throw exception(HT_PLAN_DETAILEXEANNEXS_NOT_EXISTS);
        }
    }

    @Override
    public HtPlanDetailexeannexsDO getHtPlanDetailexeannexs(Integer id) {
        return htPlanDetailexeannexsMapper.selectById(id);
    }

    @Override
    public List<HtPlanDetailexeannexsDO> getHtPlanDetailexeannexsList(Collection<Integer> ids) {
        return htPlanDetailexeannexsMapper.selectBatchIds(ids);
    }

    @Override
    public PageResult<HtPlanDetailexeannexsDO> getHtPlanDetailexeannexsPage(HtPlanDetailexeannexsPageReqVO pageReqVO) {
        return htPlanDetailexeannexsMapper.selectPage(pageReqVO);
    }

    @Override
    public List<HtPlanDetailexeannexsDO> getHtPlanDetailexeannexsList(HtPlanDetailexeannexsExportReqVO exportReqVO) {
        return htPlanDetailexeannexsMapper.selectList(exportReqVO);
    }

}
